using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication1.Models.Mapping
{
    public class SalesOrderMap : EntityTypeConfiguration<SalesOrder>
    {
        public SalesOrderMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            // Table & Column Mappings
            this.ToTable("SalesOrders");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.DateCreated).HasColumnName("DateCreated");
            this.Property(t => t.DateDispatched).HasColumnName("DateDispatched");
            this.Property(t => t.DateDelivered).HasColumnName("DateDelivered");
            this.Property(t => t.Customer_ID).HasColumnName("Customer_ID");

            // Relationships
            this.HasOptional(t => t.Customer)
                .WithMany(t => t.SalesOrders)
                .HasForeignKey(d => d.Customer_ID);

        }
    }
}
